package main

import (
	"code.google.com/p/goplan9/plan9/acme"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	winidEnv := os.Getenv("winid")
	if winidEnv == "" {
		log.Fatal("no winid")
	}

	winid, err := strconv.Atoi(winidEnv)
	if err != nil {
		log.Fatal(err)
	}

	win, err := acme.Open(winid, nil)
	if err != nil {
		log.Fatal(err)
	}

	win.ReadAddr() // make sure addr is open
	win.Ctl("addr=dot")
	q0, q1, err := win.ReadAddr()
	if err != nil {
		log.Fatal(err)
	}

	var addr string
	if q0 == q1 {
		addr = fmt.Sprintf(" :#%d", q0)
	} else {
		addr = fmt.Sprintf(" :#%d,#%d", q0, q1)
	}

	win.Write("tag", []byte(addr))
}
